import { Container } from "pixi.js";
import { Scope } from "../../../typings/traverse";
import {
  absolutePath,
  checkNamespace,
  getGoalData,
  preResAttributeLoad,
} from "../../../utils";
interface DealGoal {
  $data: Record<string, any>;
  $watcher: Record<string, Record<string, Array<Function>>>;
}
export function v_show(
  goal: DealGoal,
  container: Container,
  element: Element,
  scope: Scope | undefined
) {
  if (element.hasAttribute("v-show")) {
    const depName = "data";
    const { $data, $watcher } = goal;
    let v_show: string = <string>element.getAttribute("v-show");
    let v_showPath: string = preResAttributeLoad(v_show);
    if (scope) {
      const { item, items, key } = scope;

      let isShowNamescpce = checkNamespace(v_show, item);

      if (isShowNamescpce) {
        v_showPath = absolutePath(items, item, v_show);
      }
    }
    let isShow = getGoalData($data, v_showPath);
    if (isShow) {
      container.visible = true;
    } else {
      container.visible = false;
    }
    let showFun: Function = (val: any) => {
      if (val) {
        container.visible = true;
      } else {
        container.visible = false;
      }
    };
    $watcher[depName][v_showPath].push(showFun);
  }
}
